package conf

import (
	"github.com/BurntSushi/toml"
	"github.com/caarlos0/env"
)

var config *Config

func C() *Config {
	if config == nil {
		panic("请加载程序配置..., LoadConfigFromToml/LoadConfigFromEnv")
	}
	return config
}

func LoadConfigFromToml(path string) (*Config, error) {
	config = DefaultConfig()
	_, err := toml.DecodeFile(path, config)
	if err != nil {
		return nil, err
	}
	return config, nil
}
func LoadConfigFromEnv() (*Config, error) {
	// os.Getenv("MYSQL_DB")
	conf := DefaultConfig()
	err := env.Parse(conf)
	if err != nil {
		return nil, err
	}
	config = conf
	return nil, nil
}
